﻿//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: ITypeMappingProvider.cs
//
//  Description: Creates the mapping for a persistent type.
// 
//--------------------------------------------------------------------------

using System;
using System.Reflection;
using Chili.Opf3.Relations;

namespace Chili.Opf3.Mapping.Providers
{
	/// <summary>
	/// This interface is implemented by classes, which create the type mapping for a persistent type.
	/// </summary>
	/// <remarks>
	/// The mapping is created by compiling
	/// and returning instances of <see cref="PersistentAttribute">PersistentAttribute</see>,
	/// <see cref="FieldAttribute">FieldAttribute</see> and <see cref="RelationAttribute">RelationAttribute</see>
	/// classes. The framework uses those classes afterwards to create the <see cref="TypeMapping">TypeMapping</see>
	/// instances for the persistent types.
	/// </remarks>
	/// <example>
	///     The following example shows how to set a class that implements the ITypeMappingProvider.
	///     <code lang="CS">
	/// // Set the AttributeTypeMappingProvider that is creating the mapping by
	/// // inspecting the attriutes put on the persistent type's members.
	/// TypeMapping.Provider = new AttributeTypeMappingProvider();
	///     </code>
	/// </example>
	public interface ITypeMappingProvider
	{
		/// <summary>
		/// Returns the persistent attribute of the type or null if the type has no 
		/// <see cref="PersistentAttribute">PersistentAttribute</see>.
		/// </summary>
		/// <param name="type">Type investigated for the <see cref="PersistentAttribute">PersistentAttribute</see>.</param>
		PersistentAttribute GetPersistentAttribute(Type type);

		/// <summary>
		/// Returns the <see cref="FieldAttribute">FieldAttribute</see> for the given member. If the member is not mapped,
		/// null is returned.
		/// </summary>
		/// <param name="type">The persistent type that's mapping is created.</param>
		/// <param name="member">The member of the persistent type.</param>
		/// <returns>An instance of the <see cref="FieldAttribute">FieldAttribute</see> or null if the member is not mapped.</returns>
		FieldAttribute GetMemberFieldAttribute(Type type, MemberInfo member);

		/// <summary>
		/// Returns the <see cref="RelationAttribute">RelationAttribute</see> for the given member. If the member does not
		/// have an attribute set, null is returned.
		/// </summary>
		/// <param name="type">The persistent type that's mapping is created.</param>
		/// <param name="member">The member of the persistent type.</param>
		/// <param name="relatedType">The related object's type.</param>
		/// <returns>An instance of the <see cref="RelationAttribute">RelationAttribute</see> or null if the member does not have
		/// an attribute set.</returns>
		RelationAttribute GetMemberRelationAttribute(Type type, MemberInfo member, Type relatedType);
	}
}
